﻿using System;
using ServiceFacade;

namespace ServiceManager
{

    public class ServiceTask
    {
        public TaskStatus TaskStatus { get; set; }
        public TaskType TaskType { get; protected set; }
        public IService Service { get; set; }
        public CommandType CommandType { get; set; }

        public ServiceTask(Service service, CommandType commandType)
        {
            TaskStatus = TaskStatus.Pending;
            TaskType = TaskType.Unscheduled;
            Service = service;
            CommandType = commandType;
        }

        #region Public Methods
        public void Execute(IServiceFacade serviceFacade)
        {
            TaskStatus = TaskStatus.Running;

            try
            {
                Service.ExecuteCommand(CommandType, serviceFacade);
                TaskStatus = TaskStatus.Completed;
            }
            catch (InvalidStatusException)
            {
                TaskStatus = TaskStatus.Failed;
            }

        }
        #endregion
    }
}
